package aex.service;



import java.io.Serializable;
import java.util.LinkedHashMap;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import aex.dao.SystemAdminDao;
import aex.domain.SystemAdmin;
import aex.util.PageBean;



@Transactional(readOnly = false)
@Service(SystemAdminService.SERVICE_NAME)

public class SystemAdminService  {

	public static final String SERVICE_NAME="aex.service.AdminService";
	/**
	 * 以注解的形式让spring为我们注入dao的实现类
	 */
	@Resource(name = SystemAdminDao.SERVICE_NAME)
	private SystemAdminDao dao;

	/**
	 * 登陆检测
	 * @param art
	 */
	public SystemAdmin check(SystemAdmin admin) {
		 List<SystemAdmin> list=dao.findCollectionByConditionNoPage(" and tName.saAccount='"+admin.getSaAccount()+"'"
				+ "and tName.saPassword='"+admin.getSaPassword()+"'", null, null);
		 if(list.size()>0){
			 return list.get(0);
		 }
		 return null;
	}
	/**
	 * 更新管理员
	 */
	public void update(SystemAdmin adminLogin) {
		dao.merge(adminLogin);
	}

	
	/**
	 * 添加一个管理员
	 */
	public void save(SystemAdmin admin) {
		dao.save(admin);
	}

	/***
	 * 这个参数最好写成serializable 如果写成String那么如果主键是int就会报错
	 * @param id
	 * @return
	 */
	public SystemAdmin findById(Serializable id) {
		return dao.findObjectByID(Integer.parseInt(id+""));
	}
	
	/**
	 * 删除一个管理员
	 * @param id
	 */
	public void deleteById(Serializable id) {
		dao.deleteObjectByIDs(Integer.parseInt(id+""));
		
	}

	/**
	 * 查询所有的管理员不带分页
	 * @return
	 */
	public List<SystemAdmin> findAllManageNoPage() {
		LinkedHashMap<String, String> orderby=new LinkedHashMap<String, String>();
		orderby.put("tName.saRegisterTime", "asc");
		return dao.findCollectionByConditionNoPage("", null, orderby);
	}
	
	/**
	 * 查询所有的管理员带分页
	 */
	public PageBean<SystemAdmin> findAllManage(PageBean<SystemAdmin> pageBean) {
		LinkedHashMap<String, String> orderby=new LinkedHashMap<String, String>();
		orderby.put("tName.saRegisterTime", "asc");
		return dao.findPageBean("", null, orderby, pageBean);
	}




}
